var express = require('express');

var app = express();

var cors = require('cors');

const {default: Axios} = require('axios');

function getHoneyedWords(language) {
  var url = '';

  language = language.substr(1);

  if (language === 'pyq') {
    url = 'https://pyq.shadiao.app/api.php';
  } else if (language === 'nmsl') {
    url = 'https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn';
  } else if (language === 'chp') {
    url = 'https://chp.shadiao.app/api.php';
  } else {
    url = 'https://du.shadiao.app/api.php ';
  }

  return Axios.get(url);
}

app.use(cors());

app.listen(3000, function () {
  console.log('app is running');
});

app.get('/pyq', (request, response) => {
  console.log(111, request.url);
  getHoneyedWords(request.url.toString()).then((res) => {
    console.log(222, res.data);
    response.status(200).json(res.data);
  });
});

app.get('/nmsl', (request, response) => {
  console.log(111, request.url);
  getHoneyedWords(request.url.toString()).then((res) => {
    console.log(222, res.data);
    response.status(200).json(res.data);
  });
});

app.get('/chp', (request, response) => {
  console.log(111, request.url);
  getHoneyedWords(request.url.toString()).then((res) => {
    console.log(222, res.data);
    response.status(200).json(res.data);
  });
});

app.get('/du', (request, response) => {
  console.log(111, request.url);
  getHoneyedWords(request.url.toString()).then((res) => {
    response.status(200).json(res.data);
  });
});



